<?php
class special_listModel extends baseModel{
    protected $table = 'special_list';

    //专题内容列表
    public function special_list($limit,$where=null,$order=null) {
        $sql="
        SELECT B.*,A.*,B.title as atitle,C.name as cname
        FROM {$this->model->pre}special_list A 
        inner join {$this->model->pre}content B ON A.aid = B.aid
        inner join {$this->model->pre}special_class C ON A.cid = C.cid
        inner join {$this->model->pre}category D ON B.cid = D.cid
        WHERE B.title<>'' {$where}
        ORDER BY {$order}A.sequence ASC,A.id DESC
        LIMIT {$limit}
        ";
        $data=$this->model->query($sql);
        return $data;
    }

    public function special_count($where) {
        $sql="
            SELECT count(*) as num
            FROM {$this->model->pre}special_list A 
            inner join {$this->model->pre}content B ON A.aid = B.aid
            inner join {$this->model->pre}special_class C ON A.cid = C.cid
            inner join {$this->model->pre}category D ON B.cid = D.cid
            WHERE B.title<>'' {$where}
            ";
        $data=$this->model->query($sql);
        return $data[0]['num'];
    }

    //专题内容信息
    public function info($id) {
        return $this->find('id='.$id);
    }
    //添加专题内容
    public function add($data)
    {
        //格式化部分字段
        return $this->insert($data);
    }
    //编辑专题内容
    public function edit($data)
    {   
        //格式化部分字段
        $condition['id']=intval($data['id']);
        return $this->update($condition,$data); 
    }
    //删除专题内容
    public function del($id)
    {
        return $this->delete('id='.intval($id)); 
    }

    //通过分类删除
    public function class_del($cid)
    {
        return $this->delete('cid='.intval($cid)); 
    }

    //通过内容删除
    public function content_del($aid)
    {
        return $this->delete('aid='.intval($aid)); 
    }

    
}